package utils;
import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;


public class ConcurrentQueueAdapter<E> implements Queue<E>{
	private Queue<E> q;
	
	public ConcurrentQueueAdapter(Queue<E> implementation) {
		q = implementation;
	}

	@Override
	public boolean addAll(Collection<? extends E> c) {
		synchronized(q) {
			return q.addAll(c);	
		}
	}

	@Override
	public void clear() {
		synchronized(q) {
			q.clear();
		}
	}

	@Override
	public boolean contains(Object o) {
		synchronized(q) {
			return q.contains(o);
		}
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		synchronized(q) {
			return q.containsAll(c);
		}
	}

	@Override
	public boolean isEmpty() {
		synchronized(q) {
			return q.isEmpty();
		}
	}

	// unimplemented. Iterators are not thread safe
	@Override
	public Iterator<E> iterator() {
		return null;
	}

	@Override
	public boolean remove(Object o) {
		synchronized(q) {
			return q.remove(o);
		}
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		synchronized(q) {
			return q.removeAll(c);
		}
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		synchronized(q) {
			return q.retainAll(c);
		}
	}

	@Override
	public int size() {
		synchronized(q) {
			return q.size();
		}
	}

	@Override
	public Object[] toArray() {
		synchronized(q) {
			return q.toArray();
		}
	}

	@Override
	public <T> T[] toArray(T[] a) {
		synchronized(q) {
			return q.toArray(a);
		}
	}

	@Override
	public boolean add(E e) {
		synchronized(q) {
			return q.add(e);
		}
	}

	@Override
	public E element() {
		synchronized(q) {
			return q.element();
		}
	}

	@Override
	public boolean offer(E e) {
		synchronized(q) {
			return q.offer(e);
		}
	}

	@Override
	public E peek() {
		synchronized(q) {
			return q.peek();
		}
	}

	@Override
	public E poll() {
		synchronized(q) {
			return q.poll();
		}
	}

	@Override
	public E remove() {
		synchronized(q) {
			return q.remove();
		}
	}

}
